//
//  BDViewController.m
//  JSWaveDemo
//
//  Created by 乔同新 on 16/8/20.
//  Copyright © 2016年 乔同新. All rights reserved.

#import "BDViewController.h"
#import "JSWave.h"
#import "PersonTablCell.h"
#import "UIView+Ext.h"
#import "GuideViewController.h"
#import "UserData.h"
#import "NoTUploadSendVC.h"
#import "UploadSendVC.h"
@interface BDViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray*PersonArray;
    NSArray*Iconarray;
}
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) JSWave *headerView;

@property (nonatomic, strong) UIImageView *iconImageView;

@end

@implementation BDViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNaviBarTitle:@"个人中心"];
    [self setNavBarColor:APPNavibackColor];
    self.view.backgroundColor=[UIColor blueColor];
    self.view.backgroundColor=[UIColor groupTableViewBackgroundColor];
    PersonArray=@[@"未上传寄件单",@"已上传寄件单",@"新手指引",@"检查更新"];
    Iconarray=@[@"grzx_04",@"grzx_05",@"grzx_01",@"grzx_02"];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self.view addSubview:self.tableView];
}


- (UITableView *)tableView{
    
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, APPNaviHeight, ScreenWidth, ScreenHeight-APPNaviHeight-40-50) style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.pagingEnabled=NO;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"PersonTablCell"];
        _tableView.tableHeaderView = self.headerView;
        _tableView.tableHeaderView.backgroundColor=AppNavColor;
    }
    return _tableView;
}

- (UIImageView *)iconImageView{
    
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 200)];
        _iconImageView.layer.borderColor = [UIColor whiteColor].CGColor;
        _iconImageView.image=[UIImage imageNamed:@"Person_icon@2x.png"];
       
       
        UIImageView*IconImageV=[[UIImageView alloc]init];
        IconImageV.image=[UIImage imageNamed:@"Person@2x"];
        [_iconImageView addSubview:IconImageV];
        [IconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(_iconImageView);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(80);
        }];
        
        UILabel*UserNameLab=[[UILabel alloc]init];
        UserNameLab.text=[UserData shareUserData].userModel.name;
        UserNameLab.textAlignment=NSTextAlignmentCenter;
        
        [_iconImageView addSubview:UserNameLab];
        [UserNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-25);
            make.centerXWithinMargins.mas_equalTo(_iconImageView);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(30);
        }];
    }
    return _iconImageView;
}

- (JSWave *)headerView{
    
    if (!_headerView) {
        _headerView = [[JSWave alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,200)];
        [_headerView addSubview:self.iconImageView];
        __weak typeof(self)weakSelf = self;
        _headerView.waveBlock = ^(CGFloat currentY){
                CGRect iconFrame = [weakSelf.iconImageView frame];
                iconFrame.origin.y = CGRectGetHeight(weakSelf.headerView.frame)-CGRectGetHeight(weakSelf.iconImageView.frame)+currentY-weakSelf.headerView.waveHeight;
                weakSelf.iconImageView.frame  =iconFrame;
        };
        [_headerView startWaveAnimation];
    }
    return _headerView;
}

#pragma tab del  /  sour


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return PersonArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    PersonTablCell *Cell=[[[NSBundle mainBundle]loadNibNamed:@"PersonTablCell" owner:nil options:nil]lastObject];
    
    Cell.imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",Iconarray[indexPath.section]]];
    
    Cell.TitleLable.text=PersonArray[indexPath.section];
    
        return Cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section==0) {
        return 0;
    }if (section==2) {
        return 20;
    }
    
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.001;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section==0) {
        
    NoTUploadSendVC*NotUpload=[[NoTUploadSendVC alloc]init];
    [self.navigationController pushViewController:NotUpload animated:YES];
        
    }else if (indexPath.section==1){

    UploadSendVC*Upload=[[UploadSendVC alloc]init];
        [self.navigationController pushViewController:Upload animated:YES];
        
    }else if (indexPath.section==2){
        GuideViewController*Guid=[[GuideViewController alloc]init];
        [self.navigationController pushViewController:Guid animated:NO];
    }else if(indexPath.section==3){
        //检查更新
    }else{
    
    }
}

@end
